import * as types from '../config/storage-key.js'

/** 设置Token信息 */
const setAuthInfo = data => {
  uni.setStorageSync(types.PT_USER_AUTH_INFO, data)
}
/** 获取Token信息 */
const getAuthInfo = () => {
  const info = uni.getStorageSync(types.PT_USER_AUTH_INFO) || {}
  return info
}
/** 设置用户信息 */
const setWxUserInfo = data => {
  uni.setStorageSync(types.PT_WX_USER_INFO, data)
}
/** 获取用户信息 */
const getWxUserInfo = () => {
  const info = uni.getStorageSync(types.PT_WX_USER_INFO) || {}
  return info
}
/** 设置用户信息 */
const setUserInfo = data => {
  uni.setStorageSync(types.PT_USER_INFO, data)
}
/** 获取用户信息 */
const getUserInfo = () => {
  const info = uni.getStorageSync(types.PT_USER_INFO) || {}
  return info
}
//清楚通行证相关信息，重新授权登录
const clearAuthInfo = () => {
  uni.removeStorageSync(types.PT_USER_AUTH_INFO)
  uni.removeStorageSync(types.PT_USER_INFO)
}
// 渠道来源
const setChannel = data => {
  uni.setStorageSync(types.PT_FROM_CHANNEL, data)
}
const getChannel = () => {
  const channel = uni.getStorageSync(types.PT_FROM_CHANNEL) || 0
  return channel
}
// 子渠道涞源
const setSubChannel = data => {
  uni.setStorageSync(types.PT_SUB_CHANNEL, data)
}
const getSubChannel = () => {
  const code = uni.getStorageSync(types.PT_SUB_CHANNEL) || 0
  return code
}
// 邀请码
const setInviteCode = data => {
  uni.setStorageSync(types.PT_INVITE_CODE, data)
}
const getInviteCode = () => {
  const code = uni.getStorageSync(types.PT_INVITE_CODE) || ''
  return code
}
// 广告位参数
const setAdParams = data => {
  uni.setStorageSync(types.PT_AD_PARAMS, data)
}
const getAdParams = () => {
  const code = uni.getStorageSync(types.PT_AD_PARAMS) || ''
  return code
}
export default {
  setInviteCode,
  getInviteCode,
  setChannel,
  getChannel,
  setAuthInfo,
  getAuthInfo,
  setUserInfo,
  getUserInfo,
  setWxUserInfo,
  getWxUserInfo,
  clearAuthInfo,
  setAdParams,
  getAdParams,
  setSubChannel,
  getSubChannel
}
